//
//  ModelViewController2.m
//  test1
//
//  Created by chen on 16/11/4.
//  Copyright © 2016年 chen. All rights reserved.
//

#import "ModelViewController2.h"
#import "MyCollectionViewCell.h"

@interface ModelViewController2 () <UICollectionViewDataSource,UICollectionViewDelegate>

@property (weak, nonatomic) IBOutlet UICollectionView *collectionView;
@property (weak, nonatomic) IBOutlet UISearchBar *searchBar;
@property(nonatomic,strong)NSArray *searchList;


@end

@implementation ModelViewController2

- (void)viewDidLoad {
    [super viewDidLoad];
    
    [self loadData ];
    [self setupUI];
    
}
- (IBAction)back:(UIButton *)sender {
    [self dismissViewControllerAnimated:YES completion:nil];
}

-(void)loadData {
    NSString *path = [[NSBundle mainBundle]pathForResource:@"SearchList.plist" ofType:nil];
    NSArray *arr = [NSArray arrayWithContentsOfFile:path];
    self.searchList = arr;
    @"CityList.plist";
}

#pragma mark --datasource / delegate
-(NSInteger)collectionView:(UICollectionView *)collectionView numberOfItemsInSection:(NSInteger)section {
    return _searchList.count;
}

-(UICollectionViewCell *)collectionView:(UICollectionView *)collectionView cellForItemAtIndexPath:(NSIndexPath *)indexPath {
    MyCollectionViewCell *cell = [collectionView dequeueReusableCellWithReuseIdentifier:@"cellid" forIndexPath:indexPath];
    
    cell.label.text = _searchList[indexPath.item];
    
    return cell;
}

- (void)selectItemAtIndexPath:(nullable NSIndexPath *)indexPath animated:(BOOL)animated scrollPosition:(UICollectionViewScrollPosition)scrollPosition; {
    NSLog(@"%zd---",indexPath.item);
    
}



-(void)touchesBegan:(NSSet<UITouch *> *)touches withEvent:(UIEvent *)event {
    if (self.searchBar.isFirstResponder) {
        
        [self.searchBar resignFirstResponder];
    }
}



- (void)setupUI {
    
    
    
    [_collectionView registerClass:[MyCollectionViewCell class] forCellWithReuseIdentifier:@"cellid"];
    self.collectionView.dataSource = self;
    self.collectionView.delegate = self;
    
//    UICollectionViewCell *cell = [UICollectionViewCell ];
    
    
    
//    UICollectionViewFlowLayout *layout = [[UICollectionViewFlowLayout alloc]init];
//    layout.itemSize = CGSizeMake(self.view.bounds.size.width / 3, 50);
//    layout.minimumLineSpacing = 0;
//    layout.minimumInteritemSpacing = 0;
//    layout.scrollDirection = UICollectionViewScrollDirectionVertical;
//    
//    CGRect rect = self.view.bounds;
//    rect.origin.y = 64;
//    rect.size.height -= 64;
//    UICollectionView * cv = [[UICollectionView alloc]initWithFrame:rect collectionViewLayout:layout];
//    cv.backgroundColor = [UIColor lightGrayColor];
//    
//    cv.dataSource = self;
//    [self.view addSubview:cv];
    
}

- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}

/*
#pragma mark - Navigation

// In a storyboard-based application, you will often want to do a little preparation before navigation
- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {
    // Get the new view controller using [segue destinationViewController].
    // Pass the selected object to the new view controller.
}
*/

@end
